<?php
namespace Admin\Controller;
use Think\Controller;
use Admin\Controller\BaseController;
class ApptypeController extends BaseController {
   // private $model;
    public function _initialize(){
        $this->tbl='type';
      //  $this->model=D($this->tbl);
         $this->model=D($this->tbl);
        parent::_initialize();


    }

    public function index(){
        //$this->model=M('user');
    /*  $data=$this->model->select();
        $this->assign('list',$data);
        //dump($data);
        $this->display();*/

        parent::index($this->tbl);
    }
    
    public function view(){
        $id=I('get.id');

    }
    public function mod(){
    /*    $id = I('get.id');
        //dump($id);exit;//调试
        //$this->model=M('user');
        $one = $this->model->find($id);
        //dump($one);exit;
        $this->assign('one',$one);
        $this->display();*/
      parent::mod($this->tbl);    
    }


    public function update(){
      $data = I('post.');
        //$data['hobby']=implode(',', $data['hobby']);
        //dump($data);exit;
       // $this->model=M('type');
         //  if(!empty($_FILES['ydq_photo']['name'])){
         /*   $photo=$this->model->where ('id'=.$data['ydq_id'])->getField('ydq_photo');
            if(is_file(filename)){
                unlink();
            }
            if (is_file(filename)) {
                unlink();
                # code...
            }
            $data['ydq_photo']=$this->uploadfile('ydq_photo');
        }*/
        if($this->model->create($data)){
            $this->model->save();//用save必须有id 
            $this->success('更新成功！',U('admin.php/Apptype/index'));
        }
        else{
            $this->error('更新失败！');

        }
         /* parent::update($this->tbl,'ydq_photo');*/
    }

    public function form(){
       //test();
    //  $this->display();
        parent::form($this->tbl);  
    }

    
    public function search(){
    /*  $key=I('post.search_key');
        $sql="select * from ydq_user where ydq_username like '%".$key."%'";
        $data=M()->query($sql);
        //M()->ex
        $this->assign('user',$data);
        $this->display();*/
        parent::search($this->tbl,'ydq_typename');



    }
 /*   public function add(){
        $data = I('post.');
       // dump($_FILES);
        $data['ydq_photo']=$this->uploadfile('ydq_photo');
        $data['ydw_photo']='';
        if(!empty($_FILES['ydq_photo']['name'])){
            $data['ydq_photo']=$this->uploadfile('ydq_photo');
        }
       // dump($data);exit;
        //
        //$data['whr_username']='';
        //$data['whr_username']=I['post.username'];伪装
        $this->model = D('user');
        //dump($this->model);exit;//D方法做验证
        if ($this->model->create($data)) {
            $this->model->add();
            $this->success('创建成功！',U('admin.php/index/index'));
        }else{
            $this->error('创建失败！'.$this->model->getError());
        }
    }*/

        public function add(){
        $data = I('post.');
       // dump($_FILES);
       // $data['ydq_photo']=$this->uploadfile('ydq_photo');
       // dump($data);exit;
        //
        //$data['whr_username']='';
        //$data['whr_username']=I['post.username'];伪装
        $this->model = D('type');
        //dump($this->model);exit;//D方法做验证
        if ($this->model->create($data)) {
            $this->model->add();
            $this->success('创建成功！',U('admin.php/Apptype/index'));
        }else{
            $this->error('创建失败！'.$this->model->getError());
          /*  parent::add($this->tbl,'ydq_photo');*/
        }
    }


    public function del(){
        $id=I('get.id');
        //$this->model=M('user');
        //$this->model->del($id);
        //M('user')->del(I('get.id'))
        $result=$this->model->delete($id);
        if ($result) {
            $this->success('删除成功',U('admin.php/Apptype/index'));
            # code...
        }
        else{
            $this->error('删除失败');

        }
        /*  parent::del($this->tbl);*/

    }
/* protected function uploadfile($field,$tsize=150){
    
       $config = array(
            'maxSize'    =>   3145728,
            'rootPath'   =>   './Uploads/',
            'savePath'   =>  '',
            'saveName'   => array('uniqid',''),
            'exts'       =>   array('jpg', 'gif', 'png', 'jpeg'),

            'autoSub'    =>  true,
            'subName'    => array('date','Ymd'),
        );

        $upload = new \Think\Upload($config);// 实例化上传类
        $upload->saveName = time().'_'.mt_rand();
        // 上传单个文件 
        $info   =   $upload->uploadOne($_FILES[$field]);
        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else
        {// 上传成功 获取上传文件信息
            $image=new \Think\Image();
            $image->open($config['rootPath'].$info['savepath'].$info['savename']);
            $image->thumb($tsize,$tize,3)->save($config['rootPath'].$info['savepath'].'thumb_'.$info['savename']);
             return $info['savepath'].'thumb_'.$info['savename'];
        }
    }*/
/*    protected function uploadfile($field){
        $config = array(
            'maxSize'    =>   3145728,
            'rootPath'   =>   './Uploads/',
            'savePath'   =>  '',
            'saveName'   => array('uniqid',''),
            'exts'       =>   array('jpg', 'gif', 'png', 'jpeg'),
            'autoSub'    =>  true,
            'subName'    => array('date','Ymd'),
        );

        $upload = new \Think\Upload($config);// 实例化上传类
        $upload->saveName = time().'_'.mt_rand();
        // 上传单个文件 
        $info   =   $upload->uploadOne($_FILES[$field]);
        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else{// 上传成功 获取上传文件信息
             return $info['savepath'].$info['savename'];
        }
    }*/
}

     ?>
